package com.aplana.ccsd.model;

import info.magnolia.module.templatingkit.dam.Asset;
import info.magnolia.module.templatingkit.dam.DAMException;

import java.util.Date;

import org.apache.commons.lang.StringUtils;

/**
 * Модель заголовка статьи
 */
public class ArticleHeader {

	private final String headline;
	private final Date date;
	private final String author;
	private final String abstractText;
	private final Asset image;

	public ArticleHeader(String headline, Date date, String author,
			String abstractText, Asset image) {
		this.headline = headline;
		this.date = date;
		this.author = author;
		this.abstractText = abstractText;
		this.image = image;
	}

	public String getHeadline() {
		return headline;
	}

	public Date getDate() {
		return date;
	}

	public String getAuthor() {
		return author;
	}

	public String getAbstractText() {
		return abstractText;
	}

	public Asset getImage() {
		return image;
	}

	public boolean isHasImage() throws DAMException {
		return image != null ? (!StringUtils.isBlank(image.getLink())) : false;
	}

	public boolean isHasAbstractText() {
		return !org.apache.commons.lang.StringUtils.isBlank(abstractText);
	}

	public boolean isHasDate() {
		return date != null;
	}

	public String getFormatedDate() {
		if (date == null) {
			return null;
		}

		return com.aplana.ccsd.util.DateUtils.format(date);
	}

	@Override
	public String toString() {
		return "ArticleHeader [headline=" + headline + ", date=" + date
				+ ", author=" + author + ", abstractText=" + abstractText
				+ ", image=" + image + "]";
	}

}
